﻿#coding=utf-8
#Boa:Dialog:DlgPeerVoucher

import wx

from config import *
from product import CDataStaff,CDataAccount
from ctrlAider import *

def create(parent):
    return DlgPeerVoucher(parent)

[wxID_DLGPEERVOUCHER, wxID_DLGPEERVOUCHERBTNCANCEL, wxID_DLGPEERVOUCHERBTNOK, 
 wxID_DLGPEERVOUCHERCBACCOUNT, wxID_DLGPEERVOUCHERCBSTAFF, 
 wxID_DLGPEERVOUCHERCHECKACCOUNT, wxID_DLGPEERVOUCHERTACCOUNT, 
 wxID_DLGPEERVOUCHERTCMONEY, wxID_DLGPEERVOUCHERTHANDLER, 
 wxID_DLGPEERVOUCHERTMONEY, 
] = [wx.NewId() for _init_ctrls in range(10)]

class DlgPeerVoucher(wx.Dialog):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Dialog.__init__(self, id=wxID_DLGPEERVOUCHER, name=u'DlgPeerVoucher',
              parent=prnt, pos=wx.Point(486, 270), size=wx.Size(372, 350),
              style=wx.DEFAULT_DIALOG_STYLE, title=u'\u6536\u652f\u6b3e')
        self.SetClientSize(wx.Size(364, 316))
        self.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False,
              u'\u6977\u4f53_GB2312'))
        self.Center(wx.BOTH)

        self.tMoney = wx.StaticText(id=wxID_DLGPEERVOUCHERTMONEY,
              label=u'\u91d1\u989d\uff1a', name=u'tMoney', parent=self,
              pos=wx.Point(48, 48), size=wx.Size(56, 14), style=0)

        self.tcMoney = wx.TextCtrl(id=wxID_DLGPEERVOUCHERTCMONEY,
              name=u'tcMoney', parent=self, pos=wx.Point(104, 40),
              size=wx.Size(152, 26), style=0, value=u'')

        self.tAccount = wx.StaticText(id=wxID_DLGPEERVOUCHERTACCOUNT,
              label=u'\u8d26\u6237\uff1a', name=u'tAccount', parent=self,
              pos=wx.Point(48, 96), size=wx.Size(51, 16), style=0)

        self.cbAccount = wx.ComboBox(choices=[],
              id=wxID_DLGPEERVOUCHERCBACCOUNT, name=u'cbAccount', parent=self,
              pos=wx.Point(104, 88), size=wx.Size(150, 24), style=0, value=u'')
        self.cbAccount.SetLabel(u'')

        self.btnOK = wx.Button(id=wxID_DLGPEERVOUCHERBTNOK,
              label=u'\u786e\u5b9a', name=u'btnOK', parent=self,
              pos=wx.Point(72, 216), size=wx.Size(93, 26), style=0)
        self.btnOK.Bind(wx.EVT_BUTTON, self.OnBtnOKButton,
              id=wxID_DLGPEERVOUCHERBTNOK)

        self.btnCancel = wx.Button(id=wxID_DLGPEERVOUCHERBTNCANCEL,
              label=u'\u53d6\u6d88', name=u'btnCancel', parent=self,
              pos=wx.Point(216, 216), size=wx.Size(93, 26), style=0)
        self.btnCancel.Bind(wx.EVT_BUTTON, self.OnBtnCancelButton,
              id=wxID_DLGPEERVOUCHERBTNCANCEL)

        self.tHandler = wx.StaticText(id=wxID_DLGPEERVOUCHERTHANDLER,
              label=u'\u7ecf\u529e\u4eba\uff1a', name=u'tHandler', parent=self,
              pos=wx.Point(32, 144), size=wx.Size(68, 16), style=0)

        self.cbStaff = wx.ComboBox(choices=[], id=wxID_DLGPEERVOUCHERCBSTAFF,
              name=u'cbStaff', parent=self, pos=wx.Point(104, 136),
              size=wx.Size(150, 24), style=0, value=u'')
        self.cbStaff.SetLabel(u'')

        self.checkAccount = wx.CheckBox(id=wxID_DLGPEERVOUCHERCHECKACCOUNT,
              label=u'\u81ea\u52a8\u5728\u8d26\u6237\u660e\u7ec6\u4e2d\u6dfb\u52a0\u4e00\u6761\u8bb0\u5f55',
              name=u'checkAccount', parent=self, pos=wx.Point(104, 176),
              size=wx.Size(256, 16), style=0)
        self.checkAccount.SetValue(False)
        self.checkAccount.Show(False)

    def __init__(self, parent, pay=True):
        self._init_ctrls(parent)
        
        self.isLendout = pay
        if self.isLendout:
            self.SetTitle(u'支出')
        else:
            self.SetTitle(u'收入')
            
        self.myInit()
    
    def myInit(self):
        self.cbPayWay = MyComboBoxDecorator(self.cbAccount, CDataAccount, CDataAccount.COL_BRIEFNAME)
        self.cbPayWay.refresh()
        self.cbPayWay.SetValue(CDataAccount.getDefAccount())
        
        self.cbHandler = MyComboBoxDecorator(self.cbStaff, CDataStaff, CDataStaff.COL_NAME)
        self.cbHandler.refresh()
        self.cbHandler.SetValue(Cfg.getCurUser().getValue(CDataStaff.COL_NAME))

    def getInput(self):
        return [self.tcMoney.GetValue(), 
                self.cbPayWay.getSelectObj(), 
                self.cbHandler.getSelectObj()]
    
    
        
    def OnBtnOKButton(self, event): 
        try:
            money = float(self.tcMoney.GetValue())
            if money < 0:
                dlg = wx.MessageDialog(self, u'不允许输入负数',u'提示',wx.OK|wx.ICON_ERROR)
                dlg.ShowModal()
                return
        except:
            dlg = wx.MessageDialog(self, u'请输入正确的金额',u'提示',wx.OK|wx.ICON_ERROR)
            dlg.ShowModal()
            return

        self.EndModal(wx.ID_OK)

    def OnBtnCancelButton(self, event):
        self.EndModal(wx.ID_CANCEL)
        
        
